package com.linksfield.topup.controller.autosubmanage;

import com.alibaba.fastjson.JSON;
import com.linksfield.topup.config.dto.ResultDataDto;
import com.linksfield.topup.config.dto.StringOutputConstant;
import com.linksfield.topup.entity.interfaces.autosubmanage.search.request.RequestAutoSubscriptionSearch;
import com.linksfield.topup.entity.interfaces.autosubmanage.search.response.ResponseAutoSubscriptionSearch;
import com.linksfield.topup.service.AutoSubscriptionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RestController;

/**
 * 自动订阅管理控制器类
 *
 * @author lm
 * @date 2021/7/2 10:00
 */
@RestController
@Api(value = "自动订阅管理")
@Slf4j
public class AutoSubscriptionController {

    @Autowired
    AutoSubscriptionService autoSubscriptionService;

    @PostMapping(value = "autoSubscriptionSearch", produces = "application/json;charset=utf-8")
    @ApiOperation(value = "自动订阅管理：搜索", response = ResponseAutoSubscriptionSearch.class)
    public ResultDataDto orderSearch(@ApiParam @RequestBody RequestAutoSubscriptionSearch request,
                                     @RequestHeader(name = "x-access-token", required = false) String token) {
        log.info("【自动订阅管理搜索】请求：" + JSON.toJSONString(request));
        if (StringUtils.isBlank(token)) {
            return ResultDataDto.addOperationFailure(StringOutputConstant.CODE_TOKEN_EMPTY);
        }
        return autoSubscriptionService.search(request, token);
    }
}
